<!-- Search -->
<app-search-bar
  [submitLoading]="tableParams.loading"
  [searchOptions]="searchOptions"
  (onSearch)="queryResetData($event)"
  (onReset)="queryResetData($event)"
>
</app-search-bar>

<nz-card class="m-t-4">
  <div class="oprea-wrap">
    <button
      nz-button
      nzType="primary"
      (click)="jumpPage(0)"
    >新增加价券</button>
  </div>

  <div class="pagination-wrap-position p-t-10">
    <nz-table
      #basicTable
      nzSize="small"
      nzShowSizeChanger
      nzShowQuickJumper
      nzOuterBordered
      [nzScroll]="{ x: '1100px' }"
      [nzFrontPagination]="false"
      [nzLoadingDelay]="100"
      [nzLoading]="tableParams.loading"
      [nzData]="tableParams.tableData"
      [nzPageSizeOptions]="[5, 10, 20, 50, 100]"
      [nzTotal]="tableParams.total"
      [nzPageIndex]="tableParams.page"
      [nzPageSize]="tableParams.pageSize"
      [nzShowTotal]="totalTemplate"
      (nzPageIndexChange)="onPageIndexChange($event)"
      (nzPageSizeChange)="onPageSizeChange($event)"
    >
      <thead>
        <tr>
          <th nzAlign="center" nzWidth="120px" nzLeft>ID</th>
          <th nzAlign="center" nzWidth="180px">券码</th>
          <th nzAlign="center" nzWidth="120px">状态</th>
          <th nzAlign="center" nzWidth="120px">加价券类型</th>
          <th nzAlign="center" nzWidth="180px">前端名称</th>
          <th nzAlign="center" nzWidth="200px">备注</th>
          <th nzAlign="center" nzWidth="130px">前端展示</th>
          <th nzAlign="center" nzWidth="120px">数量</th>
          <th nzAlign="center" nzWidth="120px">适用用户</th>
          <th nzAlign="center" nzWidth="120px">适用成色</th>
          <th nzAlign="center" nzWidth="120px">适用机型</th>
          <th nzAlign="center" nzWidth="170px">发布时间</th>
          <th nzAlign="center" nzWidth="170px">更新时间</th>
          <th nzAlign="center" nzWidth="280px" nzRight>操作</th>
        </tr>
      </thead>

      <tbody>
        <tr *ngFor="let data of basicTable.data; let index = index;">
          <!-- ID -->
          <td nzAlign="center" nzLeft>{{ data.id }}</td>
          <!-- 券码 -->
          <td nzAlign="center">{{ data.no || '-' }}</td>
          <!-- 状态 -->
          <td nzAlign="center">
            <span [ngStyle]="{'color': data.status | makeupCouponStatus: 'color'}">
              {{ data.status | makeupCouponStatus: 'label' }}
            </span>
          </td>
          <!-- 加价券类型 -->
          <td nzAlign="center">
            {{ data.type === 1 ? '满加券' : '百分比券' }}
          </td>
          <!-- 前端名称 -->
          <td nzAlign="center">{{ data.name || '-' }}</td>
          <!-- 备注 -->
          <td nzAlign="center">{{ data.remark || '-' }}</td>
          <!-- 前端展示 -->
          <td nzAlign="center">
            <span [ngStyle]="{'color': data.isShowWeb === 0 ? '#F56C6C' : ''}">
              {{ data.isShowWeb === 0 ? '不展示' : '展示' }}
            </span>
          </td>
          <!-- 数量 -->
          <td nzAlign="center">{{ data.total || '0' }}</td>
          <!-- 适用用户 -->
          <td nzAlign="center">
            <div [ngSwitch]="data.userType">
              <div *ngSwitchCase="0">
                <nz-tag>通用</nz-tag>
              </div>
              <div *ngSwitchCase="1">
                <nz-tag [nzColor]="'#87d068'">C端</nz-tag>
              </div>
              <div *ngSwitchCase="2">
                <nz-tag [nzColor]="'#2db7f5'">B端</nz-tag>
              </div>
              <div *ngSwitchDefault>-</div>
            </div>
          </td>
          <!-- 适用成色 -->
          <td nzAlign="center">
            <div [ngSwitch]="data.applyColour">
              <div *ngSwitchCase="1">二手</div>
              <div *ngSwitchCase="2">准新</div>
              <div *ngSwitchDefault>全部</div>
            </div>
          </td>
          <!-- 适用机型 -->
          <td nzAlign="center">
            {{ modelToText(data.containsModel) }}
          </td>
          <!-- 发布时间 -->
          <td nzAlign="center">{{ data.releaseTime || '-' }}</td>
          <!-- 更新时间 -->
          <td nzAlign="center">{{ data.updateTime || '-' }}</td>
          <!-- 操作 -->
          <td nzAlign="center" nzRight>
            <button
              *ngIf="![5].includes(data.status)"
              nz-button
              nzType="link"
              nzSize="small"
              (click)="jumpPage(2, data)"
            >查看</button>

            <button
              nz-button
              nzType="link"
              nzSize="small"
              (click)="jumpPage(1, data)"
            >编辑</button>

            <button
              nz-button
              nzType="link"
              nzSize="small"
              (click)="jumpPage(3, data)"
            >复制</button>

            <button
              *ngIf="[1, 2].includes(data.status)"
              nz-button
              nzType="link"
              nzSize="small"
              nzDanger
              nz-popconfirm
              nzPopconfirmTitle="确认下架?"
              (nzOnConfirm)="shelfData(data)"
            >下架</button>

            <button
              *ngIf="data.status === 5"
              nz-button
              nzType="link"
              nzSize="small"
              nzDanger
              nz-popconfirm
              nzPopconfirmTitle="确认删除?"
              (nzOnConfirm)="deleteData(data)"
            >删除</button>

            <button
              *ngIf="[1, 2].includes(data.status)"
              nz-button
              nzType="link"
              nzSize="small"
              (click)="showCouponModal(data)"
            >手动发放</button>
          </td>
        </tr>
      </tbody>
    </nz-table>

    <!-- 分页template -->
    <ng-template #totalTemplate let-total>共有 {{ total }} 条</ng-template>
  </div>
</nz-card>

<!-- S 手动发放 -->
<manual-release-modal
  [(ngModel)]="releaseVisible"
  [couponCode]="opreaItem?.no"
  (submitManual)="submitManual($event)"
></manual-release-modal>
<!-- E 手动发放 -->